package com.siwei.mes.enums;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

import java.util.Arrays;

/**
 * 检定周期
 *
 * @Description: 检定周期
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/09/23 22:31
 */
@Getter
public enum VerificationCycleEnum {
    ONE_YEAR(365, "一年"),
    TWO_YEAR(730, "二年"),
    THREE_YEAR(1095, "三年"),
    UNTIL_SCRAPPING(-1, "至报废");
    @ApiModelProperty(value = "检定周期时间")
    private Integer code;
    @ApiModelProperty(value = "类型名称")
    private String name;

    VerificationCycleEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据name查找code
     *
     * @param name
     * @return
     */
    public static Integer selectByCodeName(String name) {
        VerificationCycleEnum typeEnum = Arrays.stream(values()).filter(e -> e.getName().equals(name)).findFirst().orElse(null);
        if (typeEnum == null) {
            return null;
        }
        return typeEnum.getCode();
    }
}
